package mother_arrayToStack;

/**
 * Created by xupeng20 on 2019/3/5.
 */
public class Java_Mother_ArrayToStack {
    /**
     * 用数组结构实现大小固定的队列和栈
     */
    //栈
    public static class ArrayStack{
        //固定数组
        private Integer[] arr;
        //下标
        private Integer index;
        public ArrayStack(int initSize) throws Exception {
            if (initSize<0){
                throw new Exception("");
            }
            arr = new Integer[initSize];
            index =0 ;
        }
        //加数
        public void push(int obj) throws Exception{
            if (index == arr.length){
                throw new Exception("栈满了");
            }
            arr[index++] =obj;
        }
        //减数
        public Integer pop() throws Exception{
            if (index ==0 ){
                throw new Exception("没数了");
            }
            return arr[--index];
        }

    }


    //队列


}
